package com.base.storage;

import com.base.storage.config.CloudStorageConfig;
import com.base.storage.enums.CloudStorageEnums;
import com.base.storage.provider.AliyunCloudStorageService;
import com.base.storage.provider.DiskCloudStorageService;
import com.base.storage.provider.QcloudCloudStorageService;
import com.base.storage.provider.QiniuCloudStorageService;
import com.base.storage.service.CloudStorageService;
import com.base.core.exception.ServiceException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class StorageFactory {

    //用于缓存key
    public final static String CLOUD_STORAGE_CONFIG_KEY = "CLOUD_STORAGE_CONFIG_KEY";

    @Autowired
    private CloudStorageConfig config;


    public CloudStorageService getStorage() {
        try {
            if (config.getMethods().equals(CloudStorageEnums.QINIU.getValue())) {
                return new QiniuCloudStorageService(config);
            } else if (config.getMethods().equals(CloudStorageEnums.ALIYUN.getValue())) {
                return new AliyunCloudStorageService(config);
            } else if (config.getMethods().equals(CloudStorageEnums.QCLOUD.getValue())) {
                return new QcloudCloudStorageService(config);
            } else if (config.getMethods().equals(CloudStorageEnums.DISCK.getValue())) {
                return new DiskCloudStorageService(config);
            }
        }catch (ServiceException e){
            throw e;
        }
        return null;
    }
}
